{extend name='common/common' /}

{block name="style"}
<style media="screen">
.upload-btn{
	padding: 6px;
    font-size: 26px;
}
</style>
{/block}

{block name="content"}
<el-row><el-col :md="12"><el-card class="box-card">
<!-- start -->
<div slot="header">
	<span class="span-primary"><i class="el-icon-plus"></i></span>
	添加文件
</div>
<el-form ref="form" :model="form" label-width="80px" inline>
	<el-form-item label="文件名称">
		<el-input v-model="form.name"></el-input>
	</el-form-item><br>
	<el-form-item label="重点名称">
		<el-input v-model="form.important"></el-input>
	</el-form-item><br>
	<el-form-item label="选择文件">
		<el-input v-model="form.url" disabled></el-input>
	</el-form-item>
	<el-form-item label="">
		<el-button class="upload-btn"
		@click="upFile"
		icon="fa fa-cloud-upload" type="primary" plain></el-button>
	</el-form-item><br>
	<el-form-item label="是否发布" prop="is_publish">
		<el-radio-group v-model="form.is_publish" size="small">
			<el-radio-button :label="1">是</el-radio-button>
			<el-radio-button :label="0">否</el-radio-button>
		</el-radio-group>
	</el-form-item><br>
	<el-form-item label="是否置顶" prop="is_top">
		<el-radio-group v-model="form.is_top" size="small">
			<el-radio-button :label="0">是</el-radio-button>
			<el-radio-button :label="9">否</el-radio-button>
		</el-radio-group>
	</el-form-item><br>
	<el-form-item label=" ">
		<el-button  @click="subForm" type="primary" plain>提交</el-button>
	</el-form-item>
</el-form>
<!-- end -->
</el-card></el-col></el-row>
{/block}

{block name="script"}
<script type="text/javascript">
var main = new Vue({
	el:"#main",
	data:{
		loading:false,
		form:{
			name:"",important:"",is_publish:"0",is_top:"9",url:"",attachment_id:"0"
		}
	},
	methods:{
		upFile() {
			if(this.form.name == "" && this.form.important == ""){
				this.$notify.error({title:"错误",message:"请先填写文件名称"});
				return false;
			}
			uploadAlert.is_show = true;
			uploadAlert.limit = 1;
			uploadAlert.upData = {
				targetpath:'FileDownload/' + this.form.name + this.form.important
			}
		},
		upSuccess(res){
			this.form.url = res.data.path;
			this.form.attachment_id = res.data.id;
			uploadAlert.is_show = false;
		},
		subForm() {
			var param = this.form;
			$.post("{:url('Filedownload/addFile')}",param,function(res){
				if(res.code == '1'){
					main.$notify({title:"成功",type:"success",message:res.msg});
					main.$confirm(res.msg, '成功', {
						confirmButtonText: '确定',showClose:false,type: 'success',
						showCancelButton:false
					}).then(() => {
						window.location.href = res.data;
					});
				}else{
					main.$notify.error({title:"错误",message:res.msg})
				}
			});
		}
	}
})
</script>
{/block}
